﻿using System.Runtime.InteropServices;
using System.Text;

using Microsoft.VisualStudio.TextTemplating.VSHost;

using NConfigGenerator;

namespace ConfigCodeGenerator.Package.CustomTool
{
    [Guid("244DF3DA-BEA7-4024-8CB0-05BF599CC82C")]
    public sealed class ConfigCodeCustomTool : BaseCodeGeneratorWithSite
    {
        public override string GetDefaultExtension()
        {
            return ".cs";
        }

        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            ConfigTree configTree = ConfigTree.InferFromXml(inputFileContent);
            GeneratorOptions options = new GeneratorOptions();
            options.Namespace = FileNamespace;
            string code = Generator.Generate(configTree, options);
            return Encoding.UTF8.GetBytes(code);
        }
    }
}